﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using SharpDepend.Storage.DataFormats;

namespace SharpDepend.Storage
{
    public class CustomNodeFile : CustomNode
    {
        public IDataFormat DataFormat { get; set; }

        //------------------------------------------------------------------------------------------------------------------------
        public CustomNodeFile()
            : base()
        {
            //ReadWriteTechnic = new SimpleC();
            DataFormat = new AlexBinary();
        }

        //------------------------------------------------------------------------------------------------------------------------
        public CustomNodeFile(IDataFormat readWriteTechnic)
        {
            DataFormat = readWriteTechnic;
        }

        /// <summary>
        /// Save to stream. It will not close the stream.
        /// </summary>
        /// <param name="stream">Stream to save in.</param>
        public void Save(Stream stream)
        {
            StreamWriter w = new StreamWriter(stream);
            DataFormat.InitFileStream(w.BaseStream);
            DataFormat.Save(this);
        }

        
        /// <summary>
        /// Load from stream. It will not close the stream.
        /// </summary>
        /// <param name="stream">Stream to load from.</param>
        public void Load(Stream stream)
        {
            StreamReader l = new StreamReader(stream);
            DataFormat.InitFileStream(l.BaseStream);
            DataFormat.Load(this);
        }
    }
}
